package com.google.ideas.MobileMeme;

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

/**
 * The fragment that holds our list of Streams and our action buttons.  
 * E.g., New Meme or Take Photo
 * Links to activity_stream_list.xml - the list of streams, take photo button, 
 *   and 'make a meme' button.
 */
public class StreamListFragment extends Fragment {
  private StreamListManager manager_;  
  private StreamListActivity parent_;
  // Set up the buttons.
  @Override
  public void onStart() {
    super.onStart();
    parent_ = (StreamListActivity) getActivity();
    ListView list = (ListView) getView().findViewById(R.id.stream_list_list);
    manager_ = new StreamListManager();
    manager_.ManageList(list, parent_, parent_);
    // Bind the buttons.
    Button take_picture, make_meme;
    take_picture = (Button) getView().findViewById(R.id.take_photo_btn);
    // disable the 'take a picture' button if we don't have a camera
    if (this.getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
      take_picture.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          parent_.takeAPicture();
        }
      });
    } else {
      take_picture.setEnabled(false);
    }
    make_meme = (Button) getView().findViewById(R.id.make_meme_btn);
    make_meme.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        parent_.makeAMeme();
      }
    });
  }
  
  /* 
   * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
   */
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
  }

  /* (non-Javadoc)
   * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
   */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("StreamListFragment", "StreamListFragment.onCreateView");
    return inflater.inflate(R.layout.activity_stream_list, container, false);
  }

}
